﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using BeatEmUp.Items.Weapons;

namespace BeatEmUp.HUD
{
    class HPDisplay
    {
        public static Texture2D singleHealth;
        public static Texture2D barBack;
        public Vector2 healthBarPosition{private set;get;}
        Vector2 healthBarSize;
        Rectangle healthBarRect;
        bool isDisplayed = true;

        public HPDisplay(Vector2 healthBarPosition,Vector2 healthBarSize)
        {
            this.healthBarPosition = healthBarPosition;
            this.healthBarSize = healthBarSize;
            healthBarRect = new Rectangle((int)healthBarPosition.X, (int)healthBarPosition.Y, (int)healthBarSize.X, (int)healthBarSize.Y);
        }

        public void UpdatePosition(Vector2 position)
        {
            this.healthBarPosition = position;
            healthBarRect = new Rectangle((int)healthBarPosition.X, (int)healthBarPosition.Y, (int)healthBarSize.X, (int)healthBarSize.Y);
        }

        public void Draw(SpriteBatch sb, float percent,int level)
        {
            if (isDisplayed)
            {
                GameManager.customResolution.Draw(barBack, healthBarRect, Color.White);
                string value =level.ToString("00");
                sb.DrawString(CompareWeapons.textFont,value , GameManager.customResolution.ScaleToVector(new Vector2((int)healthBarPosition.X + 2, (int)healthBarPosition.Y)), Color.White, 0, Vector2.Zero, GameManager.customResolution.ScaleRatio()-0.3f, SpriteEffects.None, 0.0f);
                GameManager.customResolution.Draw(singleHealth, new Rectangle((int)healthBarPosition.X +17, (int)healthBarPosition.Y + 1, (int)(percent * ((healthBarSize.X-16) / barBack.Width)), (int)healthBarSize.Y - 2), Color.White);
            }
        }

        public void DrawWithoutScale(SpriteBatch sb, float percent)
        {
            if (isDisplayed)
            {
                sb.Draw(barBack, healthBarRect, Color.White);
                sb.Draw(singleHealth, new Rectangle((int)healthBarPosition.X + 1, (int)healthBarPosition.Y + 1, (int)(percent * (healthBarSize.X / barBack.Width)), (int)healthBarSize.Y - 2), Color.White);
            }
        }

        public Vector2 DrawBarBackWithoutScale(SpriteBatch sb)
        {
            Rectangle rect = new Rectangle((int)healthBarRect.X, (int)healthBarRect.Y + healthBarRect.Height, healthBarRect.Width, healthBarRect.Height);
            if (isDisplayed)
            {
                sb.Draw(barBack,rect , Color.White);
            }
            return new Vector2(rect.X+3,rect.Y+2);
        }

        public bool IsDisplayed
        {
            set
            {
                isDisplayed = value;
            }
            get { return isDisplayed; }
        }
    }
}
